package com.android.hedgehog.puzzles;

import java.util.Random;

import android.util.Log;

public class DecipherWords {
	public String answerString;
	public DecipherChars dc;
	public String[] choices;
	public int totalChoices = 6;
	public int wordlength;
	String letterBank = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	Random range;
	int concrete, changer;  //concrete=answer

	public DecipherWords(int difficulty) {
		range = new Random();
		wordlength=12;
		answerString = generateAnswer(letterBank, wordlength);
		enumerateChoices();
		dc=new DecipherChars(answerString);
	}

	

	private void enumerateChoices() {

		choices = new String[totalChoices];
		concrete = range.nextInt(totalChoices); // 0-5

		for (int i = 0; i < totalChoices; i++) {
			choices[i] = answerString;
			if (i != concrete) {
				changer = range.nextInt(10); // 0-9
				Log.d("-------", i+"  :  concrete:"+concrete+"  :  choice[i]"+choices[i]+"  :  CHANGER:"+changer);
				
				while (changer>-1){// 1+ changes
					 choices[i] = changeCharacter(choices[i], letterBank);
					 changer-=4;
				 }
			}

		}

	}
	public String generateAnswer(String characters, int length) {
		char[] text = new char[length];
		for (int i = 0; i < length; i++) {
			text[i] = characters.charAt(range.nextInt(characters.length()));
		}
		return new String(text);
	}

	public String changeCharacter(String choice, String characters) {
		char oldChar = answerString.charAt(range.nextInt(wordlength));
		char newChar;
		do {
			newChar = characters.charAt(range.nextInt(characters.length()));
			Log.d("*********", "oldchar: "+oldChar+"  :  newChar:"+newChar);
		} while (oldChar == newChar);

		return choice.replace(oldChar, newChar);
	}
	

}
